package gitee.cheungming.modules.governance.util;

import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class VinGenerator {
    private static final char[] CHARS = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ".toCharArray();

    public static String generate() {
        Random random = ThreadLocalRandom.current();
        // 生成唯一序列号（17位）
        StringBuilder serial = new StringBuilder("");
        for (int i = 0; i < 17; i++) {
            serial.append(CHARS[random.nextInt(CHARS.length)]);
        }

        return serial.toString();
    }

    // 批量生成VIN号（确保唯一）
    public static List<String> generateBatch(int count) {
        return Stream.generate(VinGenerator::generate)
                .parallel()
                .distinct()
                .limit(count)
                .collect(Collectors.toList());
    }
}
